package com.intellagric.controller.module.trace_person;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.traceability.PersonVo;
import com.intellagric.pojo.TracePerson;
import com.intellagric.service.traceability.trace_person.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/11/28
 * @DESC： 人员信息管理
 */
@Controller
public class PersonController {

    @Autowired
    private PersonService personService;

    /**
     * 添加人员信息
     * @Param person
     * @return ResponseMessage
     */
    @RequestMapping("/person/add")
    @ResponseBody
    public ResponseMessage add(TracePerson person) {
        person.setId(UUID.randomUUID().toString().replaceAll("-",""));
        person.setCreateDate(new Date());
        return personService.addPerson(person);
    }


    /**
     * 删除人员信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/person/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return personService.deletePerson(id);
    }

    /**
     * 修改人员信息
     * @Param person
     * @return ResponseMessage
     */
    @RequestMapping("/person/edit")
    @ResponseBody
    public ResponseMessage edit(TracePerson person) {
        person.setUpdateDate(new Date());
        return personService.editPerson(person);
    }

    /**
     * 查询人员信息
     * @return TracePerson
     */
    @RequestMapping("/person/{id}")
    @ResponseBody
    public TracePerson get(@PathVariable String id) {
        return personService.getPersonById(id);
    }

    /**
     * 查询人员信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/person/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return personService.getPersonList();
    }

    /**
     * 分页查询人员信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/person/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page, int limit) {
        return personService.getPersonPage(page, limit);
    }

    /**
     * 多条件分页查询热人员信息表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/person/query")
    @ResponseBody
    public LayuiDataGridResult getPageByVo(int page, int limit, PersonVo personVo) {
        return personService.getPersonByVo(page, limit,personVo);
    }

}
